package com.ztesoft.web.common.customdb.dao;

import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.ztesoft.core.common.Page;
import com.ztesoft.web.common.customdb.dao.dto.ApprovaTaskStageDto;
import com.ztesoft.web.common.customdb.dao.dto.ApprovalDto;
import com.ztesoft.web.common.customdb.dao.dto.DmTaskStageDto;
import com.ztesoft.web.common.customdb.dao.mapper.IDmTaskStageCustomMapper;


@Repository("TaskStageCustomDao")
public class DmTaskStageCustomDao extends SqlSessionDaoSupport {

    @Resource(name = "majorSqlSessionTemplate")
    public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
        super.setSqlSessionTemplate(sqlSessionTemplate);
    }

    public List<DmTaskStageDto> selectTaskStageList(Integer taskId, Integer strategyId, Integer stage, String state) {
    	 return getMapper().selectTaskStageList(taskId, strategyId, stage, state);
    }
    
    public int updateTaskStage(DmTaskStageDto po) {
    	return getMapper().updateTaskStage(po);
    }
    
    public int updateTaskStageState(DmTaskStageDto po) {
    	return getMapper().updateTaskStageState(po);
    }
    public int updateTaskStageState1(DmTaskStageDto po) {
    	return getMapper().updateTaskStageState1(po);
    }
    
    public int updateTaskStageCheckCount(DmTaskStageDto po) {
    	return getMapper().updateTaskStageCheckCount(po);
    }

    public DmTaskStageDto selectByPrimaryKey(Integer dmInfoId){
		return getMapper().selectByPrimaryKey(dmInfoId);
	}
    
    public IDmTaskStageCustomMapper getMapper() {
    	return getSqlSession().getMapper(IDmTaskStageCustomMapper.class);
    }
    
	public List<ApprovalDto> selectForApproval(String planName, String checkState, Page<ApprovalDto> resultListPage) {
		if ("".equals(planName)) planName = null;
		if (null != planName) planName = "%"+planName+"%";
		return getMapper().selectListByArgAndPage(planName, "("+checkState.split(",")[2]+")", "\"("+checkState+")\"", resultListPage);
	}
	
    /**
     * 模糊查询、嵌套查询
     * @param planName
     * @param checkState
     * @return
     */
	public List<ApprovalDto> selectForApproval(String planName, String checkState) {
		if ("".equals(planName)) planName = null;
		if (null != planName) planName = "%"+planName+"%";
		return getMapper().selectLikePlanName(planName, "("+checkState.split(",")[2]+")", "\"("+checkState+")\"");
	}

	public int updateApp(ApprovaTaskStageDto taskStage) {
		// 
		return getMapper().updateApp(taskStage);
	}

	public int qryCount(Integer dmTaskId, Integer isCheck) {
		// 
		return getMapper().qryCount(dmTaskId, isCheck);
	}

	public int updateTaskStage_(int isCheck, int[] taskIdArr, String desc) {
		// 
		return getMapper().updateTaskStage_(isCheck, taskIdArr, desc);
		
	}
	public void updateStageByTaskId(Integer dmTaskId) {
		getMapper().updateStageByTaskId(dmTaskId);
	}
	
	
}
